package com.bincloud.vue.admin.web.util.request.impl;

import com.bincloud.vue.admin.common.util.IpUtils;
import com.bincloud.vue.admin.web.util.request.RequestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Description: 请求信息相关接口实现
 * @Author: bincloud, mvpzhou
 * @Date: Create By bincloud, mvpzhou on 2022/2/19
 */
@Service
@Slf4j
public class RequestServiceImpl implements RequestService {
    @Resource
    private HttpServletRequest request;

    /**
     * 获取当前请求用户名
     *
     * @return 返参
     */
    @Override
    public String getUsername() {
        return request.getUserPrincipal().getName();
    }

    /**
     * 获取IP地址
     *
     * @return 返参
     */
    @Override
    public String getIpAddress() {
        return IpUtils.getIpAddress(request);
    }
}
